package org.grow.rose.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

@Component
public class GiftButton extends JButton {
    @Autowired
    private Console console;
    @Autowired
    private Random random ;
    @Autowired
    private LightButton lightButton;
    public final static Color blue = new Color(155);
    @PostConstruct
    public void initSpring(){
        this.setText("rose");

        this.addActionListener(new ActionListener() {
//            60% 普通　30 稀有　10 传说
            @Override
            public void actionPerformed(ActionEvent e) {
//                 console.append("aaa\n");

                int i = random.nextInt(1000);
                String a ;
                Color b;
                if (i < 600){
                    a = "普通";
                    b = blue;

                }else if (i<900){
                    a="稀有";
                    b = new Color(180,0,180);
                }else {
                    a="传说";
                    b = new Color(255,255,0);
                }
                console.append("恭喜获得"+i+a+"品质的道具\n");
                lightButton.setBackground(b);

            }
        });
    }

//        this.setText("rose");






}
